#include <bits/stdc++.h>
using namespace std;
const int _ = 1e6 + 10;
const int __ = 4e6 + 10;
int n, q, arr[_], sum;
struct node {
    int mx;
    int mn;
    int ds;
} st[__];
inline node init(int val) {
    return ((node){val, val, 1});
}
inline node merg(const node& lhs, const node& rhs) {
    return ((node){max(lhs.mx, rhs.mx), min(lhs.mn, rhs.mn), max(max(lhs.ds, rhs.ds), rhs.mx - lhs.mn)});
}
#define ls ((p)<<1)
#define rs (((p)<<1)|1)
#define M (((L)+(R))>>1)
void build(int p, int L, int R) {
    if (L == R) {
        st[p] = init(arr[L]);
    } else {
        build(ls, L, M);
        build(rs, M+1, R);
        st[p] = merg(st[ls], st[rs]);
    }
}
node query(int p, int l, int r, int L, int R) {
    if (l == L && r == R) {
        return st[p];
    } else {
        if (r <= M) {
            return query(ls, l, r, L, M);
        } else if (l > M) {
            return query(rs, l, r, M+1, R);
        } else {
            return merg(query(ls, l, M, L, M), query(rs, M+1, r, M+1, R));
        }
    }
}
#undef M
#undef rs
#undef ls
int main() {
    freopen("good.in", "r", stdin);
    freopen("good.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    string str;
    cin >> str;
    for (int i = 1; i <= n; i++) {
        if (str[i-1] == '1') {
            arr[i] = arr[i-1] + 1;
        } else {
            arr[i] = arr[i-1] - 1;
        }
    }
    build(1, 0, n);
    while (q--) {
        int l, r;
        cin >> l >> r;
        l--;
        node tmp = query(1, l, r, 0, n);
        int lef = arr[l] - tmp.mn;
        int rig = tmp.mx - arr[r];
        int cnt = tmp.mx - tmp.mn - tmp.ds;
        int ans = lef + rig - min(min(lef, rig), cnt);
        (sum ^= ans);
    }
    cout << sum << endl;
    return 0;
}